package com.jeesite.modules.ele.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ele.entity.ElePhone;
import com.jeesite.modules.ele.service.ElePhoneService;

/**
 * 手机信息表Controller
 * @author ccz
 * @version 2025-03-21
 */
@Controller
@RequestMapping(value = "${adminPath}/ele/elePhone")
public class ElePhoneController extends BaseController {

	@Autowired
	private ElePhoneService elePhoneService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ElePhone get(String phoneId, boolean isNewRecord) {
		return elePhoneService.get(phoneId, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("ele:elePhone:view")
	@RequestMapping(value = {"list", ""})
	public String list(ElePhone elePhone, Model model) {
		model.addAttribute("elePhone", elePhone);
		return "modules/ele/elePhoneList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ele:elePhone:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ElePhone> listData(ElePhone elePhone, HttpServletRequest request, HttpServletResponse response) {
		elePhone.setPage(new Page<>(request, response));
		Page<ElePhone> page = elePhoneService.findPage(elePhone);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ele:elePhone:view")
	@RequestMapping(value = "form")
	public String form(ElePhone elePhone, Model model) {
		model.addAttribute("elePhone", elePhone);
		return "modules/ele/elePhoneForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("ele:elePhone:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ElePhone elePhone) {
		elePhoneService.save(elePhone);
		return renderResult(Global.TRUE, text("保存手机信息表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("ele:elePhone:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ElePhone elePhone) {
		elePhoneService.delete(elePhone);
		return renderResult(Global.TRUE, text("删除手机信息表成功！"));
	}



	@RequiresPermissions("ele:elePhone:edit")
	@RequestMapping(value = "ups")
	@ResponseBody
	public Map<String, Object> ups(@RequestBody List<String> list) {
		Map<String, Object> result = new HashMap<>();
		try {
			// 调用服务层方法
			Integer i = elePhoneService.ups(list);
			result.put("success", true);
			result.put("affectedRows", i); // 返回受影响的行数
		} catch (Exception e) {
			// 捕获异常并返回错误信息
			result.put("success", false);
			result.put("message", e.getMessage());
		}
		return result;
	}
}